package poc.spring.xml;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;

import poc.spring.model.BcsoiCacheQueryParams;


public class DdmsResourceParser {
    private BcsoiCacheQueryParams bcsoiQP;

    public DdmsResourceParser() { }
    
    public BcsoiCacheQueryParams parse(String xmlString) {
        SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
        bcsoiQP = new BcsoiCacheQueryParams();

        try {
            SAXParser saxParser = saxParserFactory.newSAXParser();
            InputStream xmlStream = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
            DdmsResourceEventHandler handler = new DdmsResourceEventHandler();

            saxParser.parse(xmlStream, handler);

//            bcsoiQP.setItemNum(iNum);
//            bcsoiQP.setQuantity(qtyy);

            
        } catch (IOException ex) {
            Logger.getLogger(DdmsResourceParser.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException e) {
            System.out.println(e.getMessage());
        } catch (SAXException e) {
            System.out.println(e.getMessage());
        }

        return bcsoiQP;
    }

}
